<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function updateInventory(arr1, arr2) {
        // 请保证你的代码考虑到所有情况
        var i, j;
        for (i = 0; i < arr2.length; i++) {
            var k = -1;
            for (j = 0; j < arr1.length; j++)
                if (arr1[j][1] == arr2[i][1]) {
                    k = j;
                    break;
                }
            if (k == -1)
                arr1.push(arr2[i]);
            else
                arr1[k][0] += arr2[i][0];
        }
        arr1.sort(
            function (a, b) {
                return a[1] > b[1] ? 1 : (a[1] < b[1] ? -1 : 0);
            });
        return arr1;
    }

    // 仓库库存示例
    var curInv = [
        [21, "Bowling Ball"],
        [2, "Dirty Sock"],
        [1, "Hair Pin"],
        [5, "Microphone"]
    ];

    var newInv = [
        [2, "Hair Pin"],
        [3, "Half-Eaten Apple"],
        [67, "Bowling Ball"],
        [7, "Toothpaste"]
    ];

    console.log(updateInventory(curInv, newInv));

</script>
</body>
</html>